home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / LAM.ICN < prev    next >
Text File  |  1992-09-28  |  3KB  |  89 lines

  1. ############################################################################
  2. #
  3. #    File:     lam.icn
  4. #
  5. #    Subject:  Program to laminate files
  6. #
  7. #    Author:   Thomas R. Hicks
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ###########################################################################
  12. #  
  13. #     This program laminates files named on the command line onto
  14. #  the standard output, producing a concatenation of corresponding
  15. #  lines from each file named.  If the files are different lengths,
  16. #  empty lines are substituted for missing lines in the shorter
  17. #  files.  A command line argument of the form - s causes the string
  18. #  s to be inserted between the concatenated file lines.
  19. #  
  20. #     Each command line argument is placed in the output line at the
  21. #  point that it appears in the argument list.  For example, lines
  22. #  from file1 and file2 can be laminated with a colon between each
  23. #  line from file1 and the corresponding line from file2 by the com-
  24. #  mand
  25. #  
  26. #          lam file1 -: file2
  27. #  
  28. #     File names and strings may appear in any order in the argument
  29. #  list.  If - is given for a file name, standard input is read at
  30. #  that point.  If a file is named more than once, each of its lines
  31. #  will be duplicated on the output line, except that if standard
  32. #  input is named more than once, its lines will be read alter-
  33. #  nately.  For example, each pair of lines from standard input can
  34. #  be joined onto one line with a space between them by the command
  35. #  
  36. #          lam - "- " -
  37. #  
  38. #  while the command
  39. #  
  40. #          lam file1 "- " file1
  41. #  
  42. #  replicates each line from file1.
  43. #  
  44. ############################################################################
  45. #
  46. #  Links: usage
  47. #
  48. ############################################################################
  49.  
  50. link usage
  51.  
  52. global fndxs
  53.  
  54. procedure main(a)
  55.    local bufs, i
  56.    bufs := list(*a)
  57.    fndxs := []
  58.    if (*a = 0) | a[1] == "?" then Usage("lam file [file | -string]...")
  59.    every i := 1 to *a do {
  60.       if a[i] == "-" then {
  61.          a[i] := &input
  62.             put(fndxs,i)
  63.             }
  64.       else if match("-",a[i]) then {
  65.          bufs[i] := a[i][2:0]
  66.          a[i] := &null
  67.          }
  68.       else {
  69.          if not (a[i] := open(a[i])) then
  70.             stop("Can't open ",a[i])
  71.          else put(fndxs,i)
  72.          }
  73.      }
  74.    if 0 ~= *fndxs then lamr(a,bufs) else Usage("lam file [file | -string]...")
  75. end
  76.  
  77. procedure lamr(args,bufs)
  78.    local i, j
  79.    every i := !fndxs do
  80.       bufs[i] := (read(args[i]) | &null)
  81.    while \bufs[!fndxs] do {
  82.       every j := 1 to *bufs do
  83.          writes(\bufs[j])
  84.       write()
  85.       every i := !fndxs do
  86.          bufs[i] := (read(args[i]) | &null)
  87.      }
  88. end
  89.